unit Unit55; 

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, LResources, Forms, Controls, Graphics, Dialogs, sqldb, db,
  DbCtrls, StdCtrls, Unit1;

type

  { TForm55 }

  TForm55 = class(TForm)
    CheckBox1: TCheckBox;
    Datasource1: TDatasource;
    DBComboBox1: TDBComboBox;
    Label1: TLabel;
    SQLQuery1: TSQLQuery;
    procedure CheckBox1Click(Sender: TObject);
    procedure DBComboBox1Select(Sender: TObject);
    procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
    procedure FormCreate(Sender: TObject);
    procedure FormShow(Sender: TObject);
  private
    { private declarations }
  public
    nombre_sucursal : string;
  end; 

var
  Form55: TForm55; 

implementation

{ TForm55 }

procedure TForm55.FormCreate(Sender: TObject);
begin
  SQLQuery1.DataBase := Form1.PQConnection1;
  SQLQuery1.Transaction := Form1.SQLTransaction1;
end;

procedure TForm55.DBComboBox1Select(Sender: TObject);
begin
  nombre_sucursal := DBComboBox1.Text;
  Close;
end;

procedure TForm55.CheckBox1Click(Sender: TObject);
begin
  nombre_sucursal := '%';

  Close;
end;

procedure TForm55.FormClose(Sender: TObject; var CloseAction: TCloseAction);
begin
  if SQLQuery1.Active = true then
    SQLQuery1.Close;

  CheckBox1.Checked := False;
end;

procedure TForm55.FormShow(Sender: TObject);
begin
  nombre_sucursal := '';
  
  if SQLQuery1.Active = True then
    SQLQuery1.Close;
    
  SQLQuery1.SQL.Text := 'select suc_nombre from sucursal order by suc_nombre';
  
  SQLQuery1.Open;
  
  DBComboBox1.Clear;
  
  DBComboBox1.DataField := 'suc_nombre';
  
  while not SQLQuery1.EOF do
  begin
    DBComboBox1.Items.Add(SQLQuery1.Fields[0].AsString);
    SQLQuery1.Next;
  end;
  
  DBComboBox1.Text := '';
  
  DBComboBox1.SetFocus
end;

initialization
  {$I unit55.lrs}

end.

